import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    TextInput,
    TouchableOpacity,
    DeviceEventEmitter,
    ScrollView
} from 'react-native';

import Constant from '../Constant/Constant'
import ScreenUtils from '../Utils/ScreenUtils'
import ColorUtils from '../Utils/ColorUtils'
import ToastUtils from '../Utils/ToastUtils'
import HttpUtils from '../Utils/HttpUtils'
import RuleUtils from '../Utils/RuleUtils'
import EncryptUtils from '../Utils/EncryptUtils'
import RouterUtils from '../Utils/RouterUtils'
import StorageUtils from '../Utils/StorageUtils'
import TimeUtils from '../Utils/TimeUtils'

export default class Templates extends React.Component
{
    static navigationOptions = ({navigation}) => ({
       gesturesEnabled:  false,//是否支持滑动返回收拾，iOS默认支持，安卓默认关闭
        headerTitle: '模版页面',
        headerStyle: {
            backgroundColor: ColorUtils.blue,
            height: ScreenUtils.statusBarHeight,
        },
        headerRight: (<Text></Text>),
        headerTintColor: ColorUtils.white,
        headerTitleStyle: {
            fontSize: ScreenUtils.Font_18,
            color: ColorUtils.white,
            fontWeight: 'normal',
            flex: 1,
            alignSelf: 'center',
            textAlign: 'center',
        }
    });

    constructor(props)
    {
        super(props);
        this.state = {
            pwd: ''
        };
    }

    componentDidMount()
    {
        RouterUtils.pushRouter('Templates', this.props.navigation.state.key);
    }

    componentWillUnmount()
    {
        RouterUtils.popRouter('Templates', this.props.navigation.state.key);
    }

    doForgetPassword()
    {
        var data = {'appId': Constant.appId, 'userPhone': this.state.userName, 'smsCode': this.state.smsCode, 'userPwd': EncryptUtils.md5(this.state.pwd) + Constant.salt};
        HttpUtils.postJson('forgetPassword', data, this.forgetPasswordSuccess.bind(this), this.forgetPasswordError.bind(this));
    }

    forgetPasswordSuccess(result)
    {
        ToastUtils.toastShortBottom(result.operation);
        this.props.navigation.goBack();
    }

    forgetPasswordError(opcode, reason)
    {
        ToastUtils.toastShortBottom(reason);
    }

    forgetPassword()
    {
        try
        {
            RuleUtils.checkPhoneRegex(this.state.userName);
            RuleUtils.checkSMSCodeRegex(this.state.smsCode);
            RuleUtils.checkPwdValid(this.state.pwd);
            this.doForgetPassword();
        }
        catch (error)
        {
            ToastUtils.toastShortBottom(error);
        }
    }

    render()
    {
        return (
            <View style={styles.container}>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: ColorUtils.bgColor,
    },
});


